﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TCM.Models;
using TCM.DbContextt;
using System.Data.Entity;

namespace TCM.Forms
{
    public partial class LoginForm : Form
    {

        private BaseContext db;

        public LoginForm()
        {
            InitializeComponent();
            db = new BaseContext();
            db.Users.Load();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            checklogin();
            if (Program.UserLogin != null)
            {
                this.Close();
            }
        }

        private void checklogin()
        {
                var user = db.Users.FirstOrDefault(x => x.Account == textBox1.Text);
                if (user != null)
                {
                    if (user.Password == textBox2.Text)
                    {
                        Program.UserId = user.UserId;
                        Program.UserLogin = user.Account;
                        return; 
                    }
                    MessageBox.Show("Вы ввели неверный пароль");
                }
                MessageBox.Show("Данного пользователя не существет");
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
